package com.sunny.ynhz.adapter;

import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sunny.ynhz.R;
import com.sunny.ynhz.bean.ProblemBean;
import com.sunny.ynhz.api.NetUrl;

import java.util.List;

/**
 * Created by luao on 2017/7/20.
 */

public class ProblemListAdapter extends BaseQuickAdapter<ProblemBean.DataBean, BaseViewHolder> {

    private RequestListener<String, GlideDrawable> requestListener = new RequestListener<String, GlideDrawable>() {
        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            // todo log exception
            Log.e("glide",e.toString());
            // important to return false so the error placeholder can be placed
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            return false;
        }
    };
    public ProblemListAdapter(@Nullable List<ProblemBean.DataBean> data) {
        super(R.layout.item_problems, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ProblemBean.DataBean item) {
        helper.setText(R.id.problem_status, item.getState());
        helper.setText(R.id.problem_addr, item.getPosition());
        helper.setText(R.id.problem_detail, item.getDescribe());
        helper.setText(R.id.problem_time, item.getTime());
        helper.setText(R.id.problem_status, item.getType());

        String imagePath = NetUrl.imageBaseUrl + item.getPicture();
        Glide.with(mContext)
                .load(imagePath)
                .error(R.mipmap.bg_header)
                .placeholder(R.drawable.bg_btn_dis)
                .listener(requestListener)
                .centerCrop()
                .into((ImageView) helper.getView(R.id.problem_photo));
    }
}
